﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
using System.Windows.Forms;

namespace DLL
{
    public class XMLHandler
    {
        public static void WRITEXML(object obj, string fileToSave, XmlSerializer serializer)
        {
            try
            {
                TextWriter writer = new StreamWriter(fileToSave);
                serializer.Serialize(writer, obj);
                writer.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(Convert.ToString(ex));
            }
        }

        public static object READXML(string fileToRead, XmlSerializer serializer)
        {
            object obj = new object();
            try
            {
                TextReader reader = new StreamReader(fileToRead);
                obj = serializer.Deserialize(reader);
                reader.Close();
                return obj;
            }
            catch (FileNotFoundException file)
            {
                return null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(Convert.ToString(ex));
                return null;
            }
        }
    }
}
